package br.edu.ufcg.embedded.eolica.connection;

import java.rmi.RemoteException;

import br.edu.ufcg.embedded.eolica.util.MyCallback;
import br.edu.ufcg.embedded.eolica.view.ErrorAlert;
import br.edu.ufcg.embedded.eolica.webservices.ArrayOfString;
import br.edu.ufcg.embedded.eolica.webservices.Eolica_PortType;
import br.edu.ufcg.embedded.eolica.webservices.Eolica_PortType_Stub;
import br.edu.ufcg.embedded.eolica.webservices.IOException;

public class GraphConnection implements Runnable {

	private MyCallback callback;
	private Eolica_PortType ws;
	private String username;
	private String password;
	private String station;
	private String graphType;
	private int height;
	private int imageWidth;
	private int imageHeigth;
	private long initDateTime;
	private long finalDateTime;
	
	public GraphConnection(MyCallback callback, String username, String password, String station, 
			int height, long initDateTime, long finalDateTime, String graphType, int imageWidth, int imageHeight) {
		
		this.callback = callback;
		ws = new Eolica_PortType_Stub();
		
		this.username = username;
		this.password = password;
		this.station = station;
		this.height = height;
		this.graphType = graphType;
		this.imageWidth = imageWidth;
		this.imageHeigth = imageHeight;
		this.initDateTime = initDateTime;
		this.finalDateTime = finalDateTime;
	}
	
	public void run() {
		try {
			System.out.println("username: " + username + " pass: " + password + " estacao: " + station + " roteiro" + " height: " +  height + " graphType: " +  graphType + " init: " +  initDateTime + "finalDate" + finalDateTime + " imageHeight: " +  imageHeigth + " imageWidth: " + imageWidth);
			//System.out.println("username: " + username + " pass: " + password + " estacao: " +  "roteiro" + " height: " +  height + " graphType: " +  graphType + " period: " +  period + " imageHeight: " +  imageHeigth + " imageWidth: " + imageWidth);
			ArrayOfString imagesBase64 = ws.getGraphics(username, password, station, height, graphType, initDateTime, finalDateTime, imageHeigth, imageWidth);
			callback.fire(imagesBase64);
		} catch (RemoteException e) {
			callback.fire(e);
		} /*catch (IOException e) {
			System.out.println("2");
			callback.fire(e);
		} */catch (Exception e) {
			callback.fire(e);
		} catch (Throwable e) {
			callback.fire(e);
		}
	}

}
